package com.ruoyi.tester.executor.expression;

import com.ruoyi.tester.executor.ExpressionContext;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author SongJun
 * @description TODO:
 * @date 2021/6/10 11:16
 */
@Component
public class ExpCurrentTime extends AbstractExpTime{

    @Override
    public String getExpressionName() {
        return "currentTime";
    }

    @Override
    public String getDescription() {
        return "currentTime() 以yyyy-MM-dd HH:mm:ss格式返回当前时间, 如: 2022-02-22 09:30:00;"+super.getDescription();
    }

    @Override
    public Object analysis(ExpressionContext context, String... param) {
        Calendar calendar = (Calendar)super.analysis(context, param);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(calendar.getTime());
    }

}
